import uvicorn
from pathlib import Path
from fastapi import FastAPI, applications
from FastApi_test import test1
from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html
# import router_marriage

app = FastAPI()


def swagger_monkey_patch(*args, **kwargs):
    return get_swagger_ui_html(
        *args, **kwargs,
        # swagger_js_url='https://cdn.bootcdn.net/ajax/libs/swagger-ui/4.10.3/swagger-ui-bundle.js',
        swagger_js_url='/static/swagger-ui-bundle.js',
        # swagger_css_url='https://cdn.bootcdn.net/ajax/libs/swagger-ui/4.10.3/swagger-ui.css'
        swagger_css_url='/static/swagger-ui.css'
    )


applications.get_swagger_ui_html = swagger_monkey_patch

# class UserIn(BaseModel):
#     username: str
#     password: str
#     email: EmailStr
#     full_name: str = None


# class UserOut(BaseModel):
#     username: str
#     email: EmailStr
#     full_name: str = None


# @app.post("/user/", response_model=UserOut)
# async def create_user(*, user: UserIn):
#     return user
#
# @app.get('/')
# def index():
#     return 'hello word1'
#
# # @app.post("/login")
# @app.api_route('/login',methods=("get","post"))
# def login(username=Form(None),password=Form(None)):
#     return {"data":{"username":username,"password":password}}
#
#
# @app.get("/list")
# def list():
#     """这是首页"""
#     return JSONResponse(content={"msg":"get user"},
#                         status_code=202,
#                         headers={"a":"b"})
#
# @app.get("/user")
# def userid(id,token=Header(None)):
#     return {"id":id,"token":token}


#
# def swagger_monkey_patch(*args, **kwargs):
#     return get_swagger_ui_html(
#         *args, **kwargs,
#         # swagger_js_url='https://cdn.bootcdn.net/ajax/libs/swagger-ui/4.10.3/swagger-ui-bundle.js',
#         swagger_js_url='/static/swagger-ui-bundle.js',
#         # swagger_css_url='https://cdn.bootcdn.net/ajax/libs/swagger-ui/4.10.3/swagger-ui.css'
#         swagger_css_url='/static/swagger-ui.css'
#     )
#
#
# applications.get_swagger_ui_html = swagger_monkey_patch
#
# 挂载静态路径
app.mount("/static", StaticFiles(directory=Path(__file__).parent.joinpath("static")), name="static")

# 组装路由
app.include_router(test1.router)


@app.on_event('startup')
def start():
    print("log")



if __name__ == '__main__':

    uvicorn.run(app="main:app", host="127.0.0.1", port=5000,reload=True)
